<template>
  <div>
    <div class="box">
      <div class="box1">
        <div class="login_name">
          <b>UNI-ADMIN</b>
        </div>
        <div class="con">
          <el-form :model="formData">
            <el-form-item>
              <el-input v-model="formData.userName" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="formData.password" placeholder="请输入密码"></el-input>
            </el-form-item>
          </el-form>
          <button @click="onClick" class="btn">立即登录</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
        formData:{
        userName:"",
        password:""
      }
    };
  },
  methods: {
      onClick(){
          axios.post("http://ceshi5.dishait.cn/admin/login",{
              username:this.formData.userName,
              password:this.formData.password
          }).then((res)=>{
              console.log(res);
              var token=res.data.data.token;
              window.localStorage.setItem("token",token)
              this.$router.push("/")
          }).catch((error)=>{
              this.$message.error("登录失败");
              console.log(error)
          })
      }
  },
};
</script>
<style scoped>
.box {
  width: 540px;
  height: 340px;
  border: 1px solid teal;
  margin: 100px auto;
  font-size: 20px;
}
.login_name {
  text-align: center;
}
.con{
    width: 500px;
  height: 260px;
  border: 1px solid rgba(0, 0, 0, 0.075);
  padding: 20px;
}
.btn{
    margin-left: 200px;
}
</style>